<?php
namespace app\api\controller\foodcash;

use app\api\controller\foodcash\Controller;
use app\api\model\foodcash\Table as TableModel;
use app\api\model\foodcash\Pact as PactModel;

/**
 * 餐桌/包间控制器
 */
class Table extends Controller
{
    /**
     * 列表
     */
    public function lists($status=0)
    {
		$model = new TableModel;
        $list = $model->getList($this->shop_id,$status);
        return $this->renderSuccess(compact('list'));
    }
    
    /**
     * 结算
     */
    public function pay($table_id)
    {
		$model = TableModel::get($table_id);
        if($model->pay()){
            return $this->renderMsg('操作成功');
        }
        $error = $model->getError() ?: '操作失败';
        return $this->renderError($error);
    }
    
    /**
     * 清台
     */
    public function clear($table_id)
    {
		$model = TableModel::get($table_id);
        if($model->clear()){
            return $this->renderMsg('操作成功');
        }
        $error = $model->getError() ?: '操作失败';
        return $this->renderError($error);
    }
    
    /**
     * 预约订桌
     */
    public function pact()
    {
		$model = new PactModel;
		$data = $this->request->post();
        $data['shop_id'] = $this->shop_id;
        $data['applet_id'] = $this->applet_id;
        $data['user_id'] = $this->user['user_id'];
        if($model->add($data)){
            return $this->renderMsg('添加成功');
        }
        $error = $model->getError() ?: '操作失败';
        return $this->renderError($error);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    /**
     * 详情
     */
    public function detail($table_id)
    {
		if ($detail = TableModel::get($table_id,['shop'])) {
            return $this->renderSuccess(compact('detail'));
        }
        return $this->renderError('餐桌/包间不存在');
    }
}
